// 全局提示框

const defaultGlobalDialog = {
  title: '',
  msg: '',
  errorMsg: '',
  redirect: '',
  centerMsg: true
};

const state = {
  showGlobalDialog: false, // 是否显示
  GlobalDialog: { ...defaultGlobalDialog }
};

const getters = {
  showGlobalDialog: (state) => state.showGlobalDialog,
  GlobalDialog: (state) => state.GlobalDialog
};

const mutations = {
  show(state, data) {
    state.showGlobalDialog = true;
    state.GlobalDialog = { ...defaultGlobalDialog, ...data };
  },
  hide(state) {
    state.showGlobalDialog = false;
    setTimeout(() => {
      state.GlobalDialog = { ...defaultGlobalDialog };
    }, 200);
  },
  temporaryHide(state) {
    state.showGlobalDialog = false;
  },
  temporaryShow(state) {
    state.showGlobalDialog = true;
  }
};

const actions = {
  pause({ state, commit }) {
    const { showGlobalDialog } = state;
    if (showGlobalDialog) {
      commit('temporaryHide');
    }
  },
  continue({ state, commit }) {
    const {
      showGlobalDialog,
      GlobalDialog: { msg }
    } = state;
    if (msg && !showGlobalDialog) {
      commit('temporaryShow');
    }
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
